<?php

use think\migration\Migrator;
use think\migration\db\Column;

/**
 * 系统管理员迁移类
 * Class SystemAdmin
 */
class SystemAdmin extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('system_admin', ['comment' => '系统管理员表', 'engine' => 'InnoDB']);
        $table->addColumn('username', 'string', ['limit' => 30, 'default' => '', 'comment' => '用户名'])
            ->addColumn('password', 'string', ['limit' => 255, 'default' => '', 'comment' => '密码'])
            ->addColumn('nickname', 'string', ['limit' => 30, 'default' => '', 'comment' => '昵称'])
            ->addColumn('avatar', 'string', ['limit' => 255, 'default' => '/static/images/avatar.png', 'comment' => '头像'])
            ->addColumn('role', 'string', ['limit' => 200, 'default' => '', 'comment' => '角色'])
            ->addColumn('reg_ip', 'string', ['limit' => 20, 'default' => '', 'comment' => '注册ip'])
            ->addColumn('reg_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP', 'comment' => '注册时间'])
            ->addColumn('last_ip', 'string', ['limit' => 20, 'default' => '', 'comment' => '最后登录ip'])
            ->addColumn('last_at', 'datetime', ['null' => true, 'comment' => '最后登录时间'])
            ->addColumn('status', 'boolean', ['limit' => 1, 'default' => 1, 'comment' => '是否启用'])
            ->addColumn('is_del', 'boolean', ['limit' => 1, 'default' => 0, 'comment' => '是否已删除 0：否 1：是'])
            ->addIndex(['is_del', 'status', 'username'])
            ->create();
    }
}
